import java.util.Arrays;

public class Java028 {
    public static void main(String[] args) {
        int[] arr={8,9,4,2,7,6,2,1,3,5};
        int[] arr1=fun1(arr);
        int[] arr2=fun2(arr);
        System.out.println(Arrays.toString(arr2));
    }
    public static int[] fun1(int[] arr){
        int[] arr1= arr.clone();
        for(int i=0;i< arr1.length;i++){
            for(int j=i+1;j<arr1.length;j++){
                if(arr1[i]>arr1[j]){
                    swap(arr1,i,j);
                }
            }
        }
        return arr1;
    }//一般选择

    public static int[] fun2(int[] arr){
        int[] arr2=(int []) arr.clone();
        int flag=0;
        while(true){
            for(int i=0;i<arr2.length-1;i++){
                if(arr2[i]>arr2[i+1]){
                    swap(arr2,i,i+1);
                    flag = i;
                }
            }
            if(flag==0){
                break;
            }
        }
        return arr2;
    }//冒泡优化
    public static void swap(int[] arr1,int i,int j){
        arr1[i]=arr1[j]+arr1[i];
        arr1[j]=arr1[i]-arr1[j];
        arr1[i]=arr1[i]-arr1[j];
    }
}
